/*
* SummaryServiceImp.java
* Created on  2015/5/28 20:13
* 版本       修改时间          作者      修改内容
* V1.0.1    2015/5/28       xfz    初始版本
*
*/

package com.infitecs.eyas.boiler.service.impl;

import com.infitecs.eyas.boiler.dao.AirGasParameterDao;
import com.infitecs.eyas.boiler.dao.EfficiencyDao;
import com.infitecs.eyas.boiler.dao.SummaryDao;
import com.infitecs.eyas.boiler.model.AirGasParameter;
import com.infitecs.eyas.boiler.model.Efficiency;
import com.infitecs.eyas.boiler.model.Summary;
import com.infitecs.eyas.boiler.service.EfficiencyService;
import com.infitecs.eyas.boiler.service.SummaryService;
import com.infitecs.eyas.expression.dao.ExpressionDao;
import com.infitecs.eyas.expression.model.Formula;
import com.infitecs.eyas.result.dao.MiddleResultDao;
import com.infitecs.eyas.result.model.MiddleResult;
import com.infitecs.eyas.util.DoubleUtil;
import com.infitecs.eyas.util.Parameter;
import com.infitecs.eyas.util.ParametersUtil;
import com.infitecs.krill.ajax.response.AjaxResponse;
import fr.expression4j.core.Expression;
import fr.expression4j.core.Parameters;
import fr.expression4j.core.exception.EvalException;
import fr.expression4j.core.exception.ParsingException;
import fr.expression4j.factory.ExpressionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;
import java.util.Set;

/**
 * 类的描述信息
 *
 * @author xfz
 * @version 1.0.1
 */
@Service("SummaryService")
@Transactional
public class SummaryServiceImp implements SummaryService{

    @Autowired
    private SummaryDao summaryDao;
    @Autowired
    private MiddleResultDao middleResultDao;
    @Autowired
    private AirGasParameterDao airGasParameterDao;
    @Autowired
    private EfficiencyService efficiencyService;
    @Autowired
    private EfficiencyDao efficiencyDao;
    @Autowired
    private ExpressionDao expressionDao;
    @Override
    public void saveTheValueOfE96(double E96, int caseId) {
        E96= DoubleUtil.getInstance().get2Double(E96);
        summaryDao.updateE96(E96,caseId);
    }
    @Override
    public void saveTheValueOfE114(double E114, int caseId) {
        E114= DoubleUtil.getInstance().get2Double(E114);
        summaryDao.updateE114(E114, caseId);
    }
    @Override
    public void saveTheValueOfE31(double E31, int caseId) {
        E31= DoubleUtil.getInstance().get2Double(E31);
        summaryDao.updateE31(E31, caseId);
    }
    @Override
    public void saveTheValueOfE115(double E115, int caseId) {
        E115= DoubleUtil.getInstance().get2Double(E115);
        summaryDao.updateE115(E115, caseId);
    }
    @Override
    public void saveTheValueOfE119(double E119, int caseId) {
        E119= DoubleUtil.getInstance().get2Double(E119);
        summaryDao.updateE119(E119, caseId);
    }
    @Override
    public void saveTheValueOfE32(double E32, int caseId) {
        E32= DoubleUtil.getInstance().get2Double(E32);
        summaryDao.updateE32(E32, caseId);
    }
    @Override
    public void saveTheValueOfE120(double E120, int caseId) {
        E120= DoubleUtil.getInstance().get2Double(E120);
        summaryDao.updateE120(E120, caseId);
    }
    @Override
    public void saveTheValueOfE101(double E101, int caseId) {
        E101= DoubleUtil.getInstance().get2Double(E101);
        summaryDao.updateE101(E101, caseId);
    }
    @Override
    public void saveTheValueOfE102(double E102, int caseId) {
        E102= DoubleUtil.getInstance().get2Double(E102);
        summaryDao.updateE102(E102, caseId);
    }
    @Override
    public void saveTheValueOfE97(double E97, int caseId) {
        E97= DoubleUtil.getInstance().get2Double(E97);
        summaryDao.updateE97(E97, caseId);
    }
    @Override
    public void saveTheValueOfE33(double E33, int caseId) {
        E33= DoubleUtil.getInstance().get2Double(E33);
        summaryDao.updateE33(E33, caseId);
    }
    @Override
    public void saveTheValueOfE98(double E98, int caseId) {
        E98= DoubleUtil.getInstance().get2Double(E98);
        summaryDao.updateE98(E98, caseId);
    }
    @Override
    public void saveTheValueOfE99(double E99, int caseId) {
        E99= DoubleUtil.getInstance().get2Double(E99);
        summaryDao.updateE99(E99, caseId);
    }
    @Override
    public void saveTheValueOfE34(double E34, int caseId) {
        E34= DoubleUtil.getInstance().get2Double(E34);
        summaryDao.updateE34(E34, caseId);
    }
    @Override
    public void saveTheValueOfE100(double E100, int caseId) {
        E100= DoubleUtil.getInstance().get2Double(E100);
        summaryDao.updateE100(E100, caseId);
    }
    @Override
    public void saveTheValueOfE42(double E42, int caseId) {
        E42= DoubleUtil.getInstance().get2Double(E42);
        summaryDao.updateE42(E42, caseId);
    }
    @Override
    public void saveTheValueOfE113(double E113, int caseId) {
        E113= DoubleUtil.getInstance().get2Double(E113);
        summaryDao.updateE113(E113, caseId);
    }
    @Override
    public void saveTheValueOfE118(double E118, int caseId) {
        E118= DoubleUtil.getInstance().get2Double(E118);
        summaryDao.updateE118(E118, caseId);
    }
    @Override
    public void saveTheValueOfE112(double E112, int caseId) {
        E112= DoubleUtil.getInstance().get2Double(E112);
        summaryDao.updateE112(E112, caseId);
    }
    @Override
    public void saveTheValueOfE130(double E130, int caseId) {
        E130= DoubleUtil.getInstance().get2Double(E130);
        summaryDao.updateE130(E130, caseId);
    }
    @Override
    public void saveTheValueOfE41(double E41, int caseId) {
        E41= DoubleUtil.getInstance().get2Double(E41);
        summaryDao.updateE41(E41, caseId);
    }
    @Override
    public void saveTheValueOfE131(double E131, int caseId) {
        E131= DoubleUtil.getInstance().get2Double(E131);
        summaryDao.updateE131(E131, caseId);
    }
    @Override
    public void saveTheValueOfE76(double E76, int caseId) {
        E76= DoubleUtil.getInstance().get2Double(E76);
        summaryDao.updateE76(E76, caseId);
    }
    @Override
    public void saveTheValueOfE110(double E110, int caseId) {
        E110= DoubleUtil.getInstance().get2Double(E110);
        summaryDao.updateE110(E110, caseId);
    }
    @Override
    public void saveTheValueOfE108(double E108, int caseId) {
        E108= DoubleUtil.getInstance().get2Double(E108);
        summaryDao.updateE108(E108, caseId);
    }
    @Override
    public void saveTheValueOfE109(double E109, int caseId) {
        E109= DoubleUtil.getInstance().get2Double(E109);
        summaryDao.updateE109(E109, caseId);
    }
    @Override
    public void saveTheValueOfE127(double E127, int caseId) {
        E127= DoubleUtil.getInstance().get2Double(E127);
        summaryDao.updateE127(E127, caseId);
    }
    @Override
    public void saveTheValueOfE126(double E126, int caseId) {
        E126= DoubleUtil.getInstance().get2Double(E126);
        summaryDao.updateE126(E126, caseId);
    }
    @Override
    public void saveTheValueOfE49(double E49, int caseId) {
        E49= DoubleUtil.getInstance().get2Double(E49);
        summaryDao.updateE49(E49, caseId);
    }
    @Override
    public void saveTheValueOfE50(double E50, int caseId) {
        E50= DoubleUtil.getInstance().get2Double(E50);
        summaryDao.updateE50(E50, caseId);
    }
    @Override
    public void saveTheValueOfE128(double E128, int caseId) {
        E128= DoubleUtil.getInstance().get2Double(E128);
        summaryDao.updateE128(E128, caseId);
    }
    @Override
    public void saveTheValueOfE129(double E129, int caseId) {
        E129= DoubleUtil.getInstance().get2Double(E129);
        summaryDao.updateE129(E129, caseId);
    }


    @Override
    public Summary getSummary(int caseId){
        AirGasParameter air=airGasParameterDao.getAirGasParameter(caseId);
        AjaxResponse ajaxResponse = efficiencyService.getEfficiencyMedian(caseId);
        Summary summary =new Summary();
        summary.setE96(getValue2(ajaxResponse,"e96"));
        summary.setE114(getValue2(ajaxResponse,"e114"));
        summary.setE115(getValue2(ajaxResponse,"e115"));
        summary.setE119(getValue2(ajaxResponse,"e119"));
        summary.setE32(DoubleUtil.getInstance().get2Double(air.getInTwiceWindTemperature()));
        summary.setE41(getValue2(ajaxResponse,"e41"));
        summary.setE49(getValue2(ajaxResponse,"e49"));
        summary.setE120(getValue2(ajaxResponse,"e120"));
        summary.setE101(getValue2(ajaxResponse,"e101"));
        summary.setE102(getValue2(ajaxResponse,"e102"));
        summary.setE97(getValue2(ajaxResponse,"e97"));
        summary.setE98(getValue2(ajaxResponse,"e98"));
        summary.setE99(getValue2(ajaxResponse,"e99"));
        summary.setE100(getValue2(ajaxResponse,"e100"));
        summary.setE33(DoubleUtil.getInstance().get2Double(air.getOutOnceWindTemperature()));
        summary.setE31(DoubleUtil.getInstance().get2Double(air.getInOnceWindTemperature()));
        summary.setE34(DoubleUtil.getInstance().get2Double(air.getOutTwiceWindTemperature()));
        summary.setE42(DoubleUtil.getInstance().get2Double(air.getOnceWindRate()));
        summary.setE113(getValue2(ajaxResponse,"e113"));
        summary.setE118(getValue2(ajaxResponse,"e118"));
        summary.setE112(getValue2(ajaxResponse,"e112"));
        summary.setE130(getValue2(ajaxResponse,"e130"));
        summary.setE131(getValue2(ajaxResponse,"e131"));
        summary.setE76(getValue2(ajaxResponse,"e76"));
        summary.setE110(getValue2(ajaxResponse,"e110"));
        summary.setE108(getValue2(ajaxResponse,"e108"));
        summary.setE109(getValue2(ajaxResponse,"e109"));
        summary.setE127(getValue2(ajaxResponse,"e127"));
        summary.setE126(getValue2(ajaxResponse,"e126"));
        summary.setE50(DoubleUtil.getInstance().get2Double(air.getOutAirTemperature()));
        summary.setE128(getValue2(ajaxResponse,"e128"));
        summary.setE129(getValue2(ajaxResponse,"e129"));
        return summary;
    }

    private double getValue2(AjaxResponse ajaxResponse, String name) {
        return DoubleUtil.getInstance().get2Double((Double) ajaxResponse.getReturnData().get(name));
    }

    @Override
    public void addSummary(int powerCaseId) {
        summaryDao.addSummary(powerCaseId);
    }


}
